package com.tools.web.work.captcha;

import com.tools.common.object.Note;

import java.util.Arrays;
import java.util.Objects;

/**
 * 点选文字图片验证码的结果包装对象
 * */
@Note("点选文字图片验证码的结果包装对象")
public class ClickCaptcha {

    @Note("图片的 Base64 编码字符串")
    private String imageBase64;

    @Note("文字、顺序、坐标的包装结果数组。依据数组顺序点击")
    private ClickChar[] chars;

    public ClickCaptcha(String imageBase64, ClickChar... chars) {
        this.setImageBase64(imageBase64);
        this.setChars(chars);
    }

    public ClickCaptcha(ClickChar... chars) {
        this.setChars(chars);
    }

    /* ********************************************************************************************
     *
     *          Getter / Setter
     *
     * *********************************************************************************************
     * */

    public String getImageBase64() {
        return imageBase64;
    }

    public void setImageBase64(String imageBase64) {
        if(imageBase64 == null) throw new NullPointerException("图片转为 Base64 字符串为空");
        this.imageBase64 = imageBase64;
    }


    public ClickChar[] getChars() {
        return chars;
    }

    public void setChars(ClickChar... chars) {
        if(chars == null || chars.length == 0) throw new NullPointerException("文字和坐标的包装实例数组为空");
        this.chars = chars;
    }

    @Override
    public String toString() {
        return "ClickCaptcha{" +
                "chars=" + Arrays.toString(chars) +
                ", imageBase64=Not Null Value" +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ClickCaptcha that = (ClickCaptcha) o;
        int length = chars.length;
        if(length != that.chars.length) return false;
        for (int i = 0; i < length; i++) {
            if (!Objects.equals(chars[i], that.chars[i])) return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        return Objects.hash(Arrays.hashCode(chars));
    }
}
